package org.genntii.warehousesystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.genntii.warehousesystem.domain.entity.User;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select count(*) from user where username = #{username}")
    int usernameIsExists(@Param("username") String username);

    @Select("select id from user where username = #{username}")
    int selectIdByUsername(@Param("username") String username);

    @Select("select password from user where username = #{username}")
    String selectPassword(@Param("username")String username);

    @Update("update user set name = #{name}, identification_number = #{identity}, last_update_time = #{lastUpdateTime} where id = #{id}")
    void realName(@Param("name") String name, @Param("identity") String identity, @Param("id")int id, @Param("lastUpdateTime")LocalDateTime time);

    @Select("select identification_number from user where id = #{id}")
    String userIsRealName(@Param("id")int id);

    @Select("select bank_account from user where id = #{id}")
    String userIsBank(@Param("id")int id);

    @Update("update user set bank_account = #{account}, bank_name = #{name}, last_update_time = #{time} where id = #{id}")
    void bank(@Param("account")String account, @Param("name")String name, @Param("id")int id, @Param("time")LocalDateTime time);

    @Select("select tel from user where id = #{id}")
    String userIsTel(@Param("id")int id);

    @Update("update user set tel = #{tel}, last_update_time = #{time} where id = #{id}")
    void tel(@Param("tel")String tel, @Param("time")LocalDateTime time, @Param("id")int id);

    @Update("update user set  commonly_used_address_id = #{commonlyAddressId} where id = #{id}")
    void addressUpdate(@Param("commonlyAddressId")int commonlyAddressId, @Param("id")int id);

    @Select("select * from user where username = #{username}")
    User selectByUsername(@Param("username")String username);

}
